package cn.gudian.cms.Message

import cn.gudian.cms.sms.SmsClient

class SmsRecord {
  String mobile;//手机号码
  String content;//发送内容
  Date sendTime;//发送时间
  Date planTime;//定时时间
  int state;//发送状态
  static mapping = {
    sort id: "desc"
    content type: 'text'
    mobile index: 'Mobile_Idx'
    sendTime index: 'SendTime_Idx,SendTimeAndState_Idx'
    state index: 'State_Idx,SendTimeAndState_Idx'
  }
  static constraints = {
    mobile(maxlength: 500);
    content();
    sendTime();
    planTime();
    state()

  }


  String stateStatesFormat() {
    return stateStates.get(state)
  }
  //需要保存短信记录的发送方法

  static void sendSems(mobiles, content) {
    def smsRecordInstance = new SmsRecord()
    String[] mobilesArry = mobiles.toString().split(",")

    int i = SmsClient.sendSMS(mobilesArry, content)
    SmsClient.closeChannel();
    smsRecordInstance.mobile = mobiles
    smsRecordInstance.content = content
    smsRecordInstance.sendTime = new Date();
    smsRecordInstance.planTime = new Date();
    smsRecordInstance.state = i;
    smsRecordInstance.save();
  }
}
